
/*-----------------------------------------------------------------------------*
* REPLICATION for "Do Provinces that Win the Spanish Christmas Lottery 
Experience a Surge in  Incumbent Popularity? An Out-of-Sample Replication of 
Bagues and Esteve-Volart (2016)". JPE Micro
* Authors: Carolina Bernal, Donald Green, and David Vilalta

* What for: Code for Provincial Vote Shares for the Incumbent Party -- Tables 1
 and 2 in the main paper and Tables A2 to A7 in the Appendix
  * Do file's author: David Vilalta
**----------------------------------------------------------------------------*/

cls

global folder "~/NEW AND FINAL REPPKG"

cd "${folder}"

use "Data/Our_data/20250531_SpanishLottery_Complete_province.dta", clear 

* Path to figures and tables folders: 
global tables "Results/Tables_Electoral/"
global figures "Results/Figures_Electoral/" 


**----------------------------------------------------------------------------**
*** Clean up, prepare globals
**----------------------------------------------------------------------------**

global controls_theirs gdp_growth_term_1 unemployment_growth_term_1 inflation_term_1 housing_price_growth_term_1
global controls_ours D_unemployment_rate_2 D_gdp_pc_2 D_housing_price_2 D_cpi_2
replace D_housing_price_2=housing_price_growth_term_1 if D_housing_price_==.
replace province = proper(province)


**----------------------------------------------------------------------------**
*** Figure 2
**----------------------------------------------------------------------------**

preserve

tostring year, gen(year_str) format(%9.0f)
gen strL prov_year = trim(province) + "-" + year_str

collapse (mean) top_prizes_gdp_term_2 total_prizes_gdp (first) year, by(prov_year)

gen strL prov_year2 = trim(prov_year)
gen byte super_prize = top_prizes_gdp_term_2 > 3.8564711

twoway ///
 (scatter top_prizes_gdp_term_2 year, mcolor(maroon) msize(medsmall) leg(off)) ///
 (scatter top_prizes_gdp_term_2 year if super_prize & prov_year2 != "Lleida-2008", ///
     msymbol(i) mlabel(prov_year2) mlabcolor(black) mlabsize(small) mlabposition(12) mlabgap(1)) ///
 (scatter top_prizes_gdp_term_2 year if prov_year2 == "Lleida-2008", ///
     msymbol(i) mlabel(prov_year2) mlabcolor(black) mlabsize(small) mlabposition(6) mlabgap(1)) ///
 , xtitle("Election") ytitle("Top Prizes as % of GDP") graphregion(color(white))

restore

**----------------------------------------------------------------------------**
*** REGRESSIONS IN BAGUES AND ESTEVE-VOLART (2016)
**----------------------------------------------------------------------------**

* No population weights

eststo col_2_p: reg var_votes_inc_reppkg top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year, robust 
summarize var_votes_inc_reppkg if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Repl."
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\times$"
estadd local Pop_weights "$\times$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_3_p: reg var_votes_inc_reppkg top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_theirs, robust
summarize var_votes_inc_reppkg if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Repl."
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_4_p: reg var_votes_inc_reppkg top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_theirs i.province_num, robust
summarize var_votes_inc_reppkg if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Repl."
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_4_p_exsort: reg var_votes_inc_reppkg top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_theirs i.province_num, robust, if province!="Lleida"
summarize var_votes_inc_reppkg if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Repl."
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Pre-09"
estadd local Sample2 "Ex-Lleida"

* Population weights

eststo col_2_p_pw: reg var_votes_inc_reppkg top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year [pw=population], robust
summarize var_votes_inc_reppkg [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Repl."
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\times$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_3_p_pw: reg var_votes_inc_reppkg top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_theirs i.year [pw=population], robust
summarize var_votes_inc_reppkg [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Repl."
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_4_p_pw: reg var_votes_inc_reppkg top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_theirs i.year i.province_num [pw=population], robust
summarize var_votes_inc_reppkg [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Repl."
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_4_p_pw_exsort: reg var_votes_inc_reppkg top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_theirs i.year i.province_num [pw=population], robust, if province!="Lleida"
summarize var_votes_inc_reppkg [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Repl."
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Pre-09"
estadd local Sample2 "Ex-Lleida"


**----------------------------------------------------------------------------**
*** OUR REGRESSIONS (POOLED)
**----------------------------------------------------------------------------**

* Temporarily renaming variables to be able to them togather in the same table
rename top_prizes_gdp_term_1 dummmy
rename top_prizes_gdp_term_2 top_prizes_gdp_term_1
rename expenditure_gdp_term_1 dummy2
rename expenditure_gdp_term_2 expenditure_gdp_term_1

* No population weights
eststo col_2: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year, robust
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\times$"
estadd local Pop_weights "$\times$"
estadd local Sample "All"
estadd local Sample2 "All"

eststo col_3: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours, robust
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "All"
estadd local Sample2 "All"

eststo col_4: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num, robust
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "All"
estadd local Sample2 "All"

eststo col_4_exsort: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num, robust, if province!="Lleida"
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "All"
estadd local Sample2 "Ex. Lleida"

* Population weights
eststo col_2_pw: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year [pw=population], robust
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\times$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "All"
estadd local Sample2 "All"

eststo col_3_pw: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours [pw=population], robust
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "All"
estadd local Sample2 "All"

eststo col_4_pw: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num [pw=population], robust
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "All"
estadd local Sample2 "All"

eststo col_4_pw_exsort: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num [pw=population], robust, if province!="Lleida"
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "All"
estadd local Sample2 "Ex. Lleida"

* Renaming back to original names
rename expenditure_gdp_term_1 expenditure_gdp_term_2
rename top_prizes_gdp_term_1 top_prizes_gdp_term_2 
rename dummy2 expenditure_gdp_term_1 
rename dummmy top_prizes_gdp_term_1


**----------------------------------------------------------------------------**
*** OUR REGRESSIONS (OUT-OF-SAMPLE)
**----------------------------------------------------------------------------**

* Temporarily renaming variables to be able to them togather in the same table
rename top_prizes_gdp_term_1 dummmy
rename top_prizes_gdp_term_2 top_prizes_gdp_term_1
rename expenditure_gdp_term_1 dummy2
rename expenditure_gdp_term_2 expenditure_gdp_term_1

* No population weights

eststo col_2_post: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year, robust, if year>2008
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\times$"
estadd local Pop_weights "$\times$"
estadd local Sample "Post-08"
estadd local Sample2 "All"

eststo col_3_post: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours, robust, if year>2008
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Post-08"
estadd local Sample2 "All"

eststo col_4_post: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num, robust, if year>2008
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Post-08"
estadd local Sample2 "All"

eststo col_4_post_exsort: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num, robust, if year>2008 & province!="Lleida"
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Post-08"
estadd local Sample2 "Ex-Lleida"

* Population weights

eststo col_2_pw_post: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year [pw=population], robust, if year>2008
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\times$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Post-08"
estadd local Sample2 "All"

eststo col_3_pw_post: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours [pw=population], robust, if year>2008 
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Post-08"
estadd local Sample2 "All"

eststo col_4_pw_post: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num [pw=population], robust, if year>2008 
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Post-08"
estadd local Sample2 "All"

eststo col_4_pw_post_exsort: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num [pw=population], robust, if year>2008 & province!="Lleida"
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Post-08"
estadd local Sample2 "Ex-Lleida"

* Renaming back to original names
rename expenditure_gdp_term_1 expenditure_gdp_term_2
rename top_prizes_gdp_term_1 top_prizes_gdp_term_2 
rename dummy2 expenditure_gdp_term_1 
rename dummmy top_prizes_gdp_term_1


**----------------------------------------------------------------------------**
*** OUR REGRESSIONS (REPLICATION PERIOD)
**----------------------------------------------------------------------------**

* Temporarily renaming variables to be able to put them togather in the same table
rename top_prizes_gdp_term_1 dummmy
rename top_prizes_gdp_term_2 top_prizes_gdp_term_1
rename expenditure_gdp_term_1 dummy2
rename expenditure_gdp_term_2 expenditure_gdp_term_1

* No population weights
eststo col_2_pre: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year, robust, if year<2009
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\times$"
estadd local Pop_weights "$\times$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_3_pre: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours, robust, if year<2009
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_4_pre: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num, robust, if year<2009
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_4_pre_exsort: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num, robust, if year<2009 & province!="Lleida"
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Pre-09"
estadd local Sample2 "Ex-Lleida"

* Population weights
eststo col_2_pw_pre: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year [pw=population], robust, if year<2009
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\times$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_3_pw_pre: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours [pw=population], robust, if year<2009 
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\times$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_4_pw_pre: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num [pw=population], robust, if year<2009
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo col_4_pw_pre_exsort: reg var_votes_inc_ours top_prizes_gdp_term_1 c.expenditure_gdp_term_1##i.year $controls_ours i.province_num [pw=population], robust, if year<2009 & province!="Lleida"
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Pre-09"
estadd local Sample2 "Ex-Lleida"

* Renaming back to original names
rename expenditure_gdp_term_1 expenditure_gdp_term_2
rename top_prizes_gdp_term_1 top_prizes_gdp_term_2 
rename dummy2 expenditure_gdp_term_1 
rename dummmy top_prizes_gdp_term_1


**----------------------------------------------------------------------------**
*** OUR REGRESSIONS - ONLY SAME YEAR'S PRIZES AND EXPENDITURE
**----------------------------------------------------------------------------**

* No population weights

eststo pre_npw_all: reg var_votes_inc_ours top_prizes_gdp_ours_c c.expenditure_gdp_ours_c##i.year $controls_ours i.province_num, robust, if year<2009
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo post_npw_all: reg var_votes_inc_ours top_prizes_gdp_ours_c c.expenditure_gdp_ours_c##i.year $controls_ours i.province_num, robust, if year>2008
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "Post-08"
estadd local Sample2 "All"

eststo all_npw_all: reg var_votes_inc_ours top_prizes_gdp_ours_c c.expenditure_gdp_ours_c##i.year $controls_ours i.province_num, robust
summarize var_votes_inc_ours if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\times$"
estadd local Sample "All"
estadd local Sample2 "All"


* Population weights
eststo pre_pw_all: reg var_votes_inc_ours top_prizes_gdp_ours_c c.expenditure_gdp_ours_c##i.year $controls_ours i.province_num [pw=population], robust, if year<2009
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Pre-09"
estadd local Sample2 "All"

eststo post_pw_all: reg var_votes_inc_ours top_prizes_gdp_ours_c c.expenditure_gdp_ours_c##i.year $controls_ours i.province_num [pw=population], robust, if year>2009
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "Post-08"
estadd local Sample2 "All"

eststo all_pw_all: reg var_votes_inc_ours top_prizes_gdp_ours_c c.expenditure_gdp_ours_c##i.year $controls_ours i.province_num [pw=population], robust
summarize var_votes_inc_ours [aweight=population] if e(sample), meanonly
estadd scalar MeanDV = r(mean)
estadd local Estimation "OLS"
estadd local Data "Ours"
estadd local Year "$\checkmark$"
estadd local Province "$\checkmark$"
estadd local Cluster "$\times$"
estadd local Controls "$\checkmark$"
estadd local Pop_weights "$\checkmark$"
estadd local Sample "All"
estadd local Sample2 "All"


**----------------------------------------------------------------------------**
*** TABLES
**----------------------------------------------------------------------------**
		
* Table 1 - Estimated Effects of Lottery Winnings on Province-Level Vote Share for the Incumbent Party, by Period and Weighting Scheme	
esttab col_4_pre col_4_pw_pre col_4_post col_4_pw_post col_4 col_4_pw using ${tables}electoral_results_consolidated.tex, ///
		keep(top_prizes_gdp_term_1)  ///
		nocon r2 ///
		mtitles se mtitles("Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb.")  ///
		coeflabels(top_prizes_gdp_term_1 "Cumulative Top Prizes")  ///
					scalars("MeanDV Outcome Mean" "Estimation Estimation" "Data Data" "Year Expenditure x Year FEs" "Province Province FEs" "Controls Controls" "Cluster Cluster Province" "Pop_weights Pop. Weights" "Sample Sample" "Sample2 Observations")  ///
        star(* 0.05 ** 0.01) b(%9.3f) replace	
		

* Table 2 - Estimated Effects of Lottery Winnings (Defining Prizes based on the Latest Lottery) on Province-Level Vote Share for the Incumbent Party, by Period and Weighting Scheme	
esttab pre_npw_all pre_pw_all post_npw_all post_pw_all all_npw_all all_pw_all using ${tables}electoral_results_consolidated_samey.tex, ///
		keep(top_prizes_gdp_ours_c)  ///
		nocon r2 ///
		mtitles se mtitles("Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb.")  ///
		coeflabels(top_prizes_gdp_ours_c "Prev. Year Top Prizes")  ///
					scalars("MeanDV Outcome Mean" "Estimation Estimation" "Data Data" "Year Expenditure x Year FEs" "Province Province FEs" "Controls Controls" "Cluster Cluster Province" "Pop_weights Pop. Weights" "Sample Sample" "Sample2 Observations")  ///
        star(* 0.05 ** 0.01) b(%9.3f) replace	
		

* Table A2 - Estimated Effects of Lottery Winnings on Province-Level Vote Share for the Incumbent Party, Unweighted, Replication Period (1989–2008)		
esttab col_2_p col_2_pre col_3_p col_3_pre col_4_p col_4_pre col_4_p_exsort col_4_pre_exsort using ${tables}electoral_results_our_data_old_pre_inter.tex, ///
		keep(top_prizes_gdp_term_1)  ///
		nocon r2 ///
		mtitles se mtitles("Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb.")  ///
		coeflabels(top_prizes_gdp_term_1 "Cumulative Top Prizes")  ///
					scalars("MeanDV Outcome Mean" "Estimation Estimation" "Data Data" "Year Expenditure x Year FEs" "Province Province FEs" "Controls Controls" "Cluster Cluster Province" "Pop_weights Pop. Weights" "Sample Sample" "Sample2 Observations")  ///
        star(* 0.05 ** 0.01) b(%9.3f) replace

		
* Table A3 - Estimated Effects of Lottery Winnings on Province-Level Vote Share for the Incumbent Party, Weighted by Provincial Population, Replication Period (1989–2008)		
esttab col_2_p_pw col_2_pw_pre col_3_p_pw col_3_pw_pre col_4_p_pw col_4_pw_pre col_4_p_pw_exsort col_4_pw_pre_exsort using ${tables}electoral_results_our_data_old_pw_pre_inter.tex, ///
		keep(top_prizes_gdp_term_1)  ///
		nocon r2 ///
		mtitles se mtitles("Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb.")  ///
		coeflabels(top_prizes_gdp_term_1 "Cumulative Top Prizes")  ///
					scalars("MeanDV Outcome Mean" "Estimation Estimation" "Data Data" "Year Expenditure x Year FEs" "Province Province FEs" "Controls Controls" "Cluster Cluster Province" "Pop_weights Pop. Weights" "Sample Sample" "Sample2 Observations")  ///
        star(* 0.05 ** 0.01) b(%9.3f) replace


* Table A4 - Estimated Effects of Lottery Winnings on Province-Level Vote Share for the Incumbent Party, Unweighted, Out-of-Sample Period (2011–2023)
esttab col_2_p col_2_post col_3_p col_3_post col_4_p col_4_post col_4_p_exsort col_4_post_exsort using ${tables}electoral_results_our_data_old_post_inter.tex, ///
		keep(top_prizes_gdp_term_1)  ///
		nocon r2 ///
		mtitles se mtitles("Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb.")  ///
		coeflabels(top_prizes_gdp_term_1 "Cumulative Top Prizes")  ///
					scalars("MeanDV Outcome Mean" "Estimation Estimation" "Data Data" "Year Expenditure x Year FEs" "Province Province FEs" "Controls Controls" "Cluster Cluster Province" "Pop_weights Pop. Weights" "Sample Sample" "Sample2 Observations")  ///
        star(* 0.05 ** 0.01) b(%9.3f) replace

		
* Table A5 - Estimated Effects of Lottery Winnings on Province-Level Vote Share for the Incumbent Party, Weighted by Provincial Population, Out-of-Sample Period (2011–2023)		
esttab col_2_p_pw col_2_pw_post col_3_p_pw col_3_pw_post col_4_p_pw col_4_pw_post col_4_p_pw_exsort col_4_pw_post_exsort using ${tables}electoral_results_our_data_old_pw_post_inter.tex, ///
		keep(top_prizes_gdp_term_1)  ///
		nocon r2 ///
		mtitles se mtitles("Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb.")  ///
		coeflabels(top_prizes_gdp_term_1 "Cumulative Top Prizes")  ///
					scalars("MeanDV Outcome Mean" "Estimation Estimation" "Data Data" "Year Expenditure x Year FEs" "Province Province FEs" "Controls Controls" "Cluster Cluster Province" "Pop_weights Pop. Weights" "Sample Sample" "Sample2 Observations")  ///
        star(* 0.05 ** 0.01) b(%9.3f) replace

		
* Table A6 - Estimated Effects of Lottery Winnings on Province-Level Vote Share for the Incumbent Party, Unweighted, Pooled (1989-2023)		
esttab col_2_p col_2 col_3_p col_3 col_4_p col_4 col_4_p_exsort col_4_exsort using ${tables}electoral_results_our_data_old_inter.tex, ///
		keep(top_prizes_gdp_term_1)  ///
		nocon r2 ///
		mtitles se mtitles("Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb.")  ///
		coeflabels(top_prizes_gdp_term_1 "Cumulative Top Prizes")  ///
					scalars("MeanDV Outcome Mean" "Estimation Estimation" "Data Data" "Year Expenditure x Year FEs" "Province Province FEs" "Controls Controls" "Cluster Cluster Province" "Pop_weights Pop. Weights" "Sample Sample" "Sample2 Observations")  ///
        star(* 0.05 ** 0.01) b(%9.3f) replace


* Table A7 - Estimated Effects of Lottery Winnings on Province-Level Vote Share for the Incumbent Party, Weighted by Provincial Population, Pooled (1989-2023)		
esttab col_2_p_pw col_2_pw col_3_p_pw col_3_pw col_4_p_pw col_4_pw col_4_p_pw_exsort col_4_pw_exsort using ${tables}electoral_results_our_data_old_pw_inter.tex, ///
		keep(top_prizes_gdp_term_1)  ///
		nocon r2 ///
		mtitles se mtitles("Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb." "Vote Incumb.")  ///
		coeflabels(top_prizes_gdp_term_1 "Cumulative Top Prizes")  ///
					scalars("MeanDV Outcome Mean" "Estimation Estimation" "Data Data" "Year Expenditure x Year FEs" "Province Province FEs" "Controls Controls" "Cluster Cluster Province" "Pop_weights Pop. Weights" "Sample Sample" "Sample2 Observations")  ///
        star(* 0.05 ** 0.01) b(%9.3f) replace
		
		
**----------------------------------------------------------------------------**
*** CHOW TEST
**----------------------------------------------------------------------------**
		
gen chow_xvar=.
replace chow_xvar = top_prizes_gdp_term_1 if year<2009
replace chow_xvar = top_prizes_gdp_term_2 if year>2009

gen chow_xvar2=.
replace chow_xvar2 = expenditure_gdp_term_1 if year<2009
replace chow_xvar2 = expenditure_gdp_term_2 if year>2009

generate group=.
replace group=1 if year<2009
replace group=2 if year>2009

global controls_ours D_unemployment_rate_2 D_gdp_pc_2 D_housing_price_2 D_cpi_2


* Chow test for treatment only

reg var_votes_inc_ours c.chow_xvar##i.group c.chow_xvar2##i.year $controls_ours i.province_num, robust
testparm i.group#c.chow_xvar


* Chow test for structural change

reg var_votes_inc_ours ///
    c.chow_xvar##i.group ///
    c.D_unemployment_rate_2##i.group ///
    c.D_gdp_pc_2##i.group ///
    c.D_housing_price_2##i.group ///
    c.D_cpi_2##i.group ///
    c.chow_xvar2##i.year##i.group ///
    i.province_num##i.group, robust

testparm i.group#c.*
testparm i.group#c.chow_xvar
